******************************************************************************************
/*	December 28, 2020
	Replication run using Stata 16
	
	Gonzales, León-Ciliotta and Martínez, "How Effective Are Monetary Incentives to Vote? Evidence from a Nationwide Policy"
	This file replicates Tables 1-6, Appendix Tables A1, B1-B4, C1-C3, D1-D5, F1-F2, Figures 1-3, 5, Appendix Figures A1-A2, B1-B3, D1
*/
******************************************************************************************
clear
clear matrix
clear mata
set maxvar  32767 
set matsize 11000

*global dir "" // If running this do-file on its own, make sure to first run program "Stata_setup", then run program "Data_elect" to create the necessary data files and use global dir to specify the correct path”. 
global P_INTERMEDIATE "Replication_files/Data/INTERMEDIATE"
global P_CLEAN "Replication_files/Data/CLEAN"
global P_RESULTS "Replication_files/Results"

cd "${dir}"

use "$P_CLEAN/Elections.dta",clear

******************************************************************************************
*Table 1: The Marginal Effect of the Abstention Fine on Voter Turnout
******************************************************************************************
*Panel A
global out outreg2 using "$P_RESULTS\Tables\Table1_a.tex", bracket nocons nor2 keep(fine_a) dec(3)
reghdfe turnout fine_a  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election FE, No, Weighted, Yes, Election-Poor/Extreme poor share FE, No)
reghdfe turnout fine_a  [aweight=electores_01],absorb(ubigeo date) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts,`M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, No, Election-Province FE, No, Election FE, Yes, Election-Poor/Extreme poor share FE, No)
reghdfe turnout fine_a [aweight=electores_01],absorb(ubigeo i.date#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts,`M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, No, Election-Province FE, Yes, Election FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe turnout fine_a  ,absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample)  
${out}   addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, No,District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe turnout fine_a c.non_extreme#i.date c.extreme#i.date  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe turnout fine_a share_primaria share_sec share_univ  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No,Election FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe turnout fine_a ln_local  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No,Election FE, No, Election-Poor/Extreme poor share FE, No) tex(frag)

*Panel B
global out outreg2 using "$P_RESULTS\Tables\Table1_b.tex", bracket nocons nor2 keep(ln_fine) dec(3)
reghdfe ln_turnout ln_fine  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election FE, No, Weighted, Yes, Election-Poor/Extreme poor share FE, No)
reghdfe ln_turnout ln_fine  [aweight=electores_01],absorb(ubigeo date) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, No, Election-Province FE, No, Election FE, Yes, Election-Poor/Extreme poor share FE, No)
reghdfe ln_turnout ln_fine  [aweight=electores_01],absorb(ubigeo i.date#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, No, Election-Province FE, Yes, Election FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe ln_turnout ln_fine  ,absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1] 
sum `e(depvar)' if e(sample) 
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, No, District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe ln_turnout ln_fine c.non_extreme#i.date c.extreme#i.date  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe ln_turnout ln_fine share_primaria share_sec share_univ  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election-Poor/Extreme poor share FE, No)
reghdfe ln_turnout ln_fine ln_local  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts,`M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(Weighted, Yes, District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Election-Poor/Extreme poor share FE, No) tex(frag)

******************************************************************************************
*Table 2: Heterogeneous Effects of the Abstention Fine on Voter Turnout
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\Table2.tex", bracket nocons nor2 dec(3)
reghdfe turnout fine_a fine_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2016==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")
reghdfe turnout fine_a fine_r2  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_r2==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")
reghdfe turnout fine_a fine_any_poor  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_any_poor==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")

preserve
replace turnout=ln_turnout
replace fine_a=ln_fine
replace fine_2016=lfine_2016
replace fine_r2=lfine_r2
replace fine_any_poor = lfine_any_poor
reghdfe turnout fine_a fine_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2016==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'") ctitle(elasticity)
reghdfe turnout fine_a fine_r2  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_r2==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'") ctitle(elasticity)
reghdfe turnout fine_a fine_any_poor  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_any_poor==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'") ctitle(elasticity)
restore

******************************************************************************************
*Table 3: The Marginal Effect of the Abstention Fine on Voter Registration by Age
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\Table3.tex", bracket nocons nor2 dec(3)
reghdfe ln_electores ln_fine if runoff==0&year!=2006 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace ctitle(full) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)

preserve
drop if year==2006
reghdfe ln_entre_18_20 ln_fine if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} ctitle(18-20) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_entre_21_29 ln_fine if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle(21-29) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_entre_30_35 ln_fine if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle(30-35) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_entre_36_50 ln_fine if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle(36-50) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_entre_51_75 ln_fine if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle(51-75) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_mayores_75 ln_fine if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle(75+) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) tex(frag)
restore

******************************************************************************************
*Table 4: The Marginal Effect of the Abstention Fine on Voter Registration
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\Table4.tex", bracket nocons nor2 dec(3)
reghdfe ln_electores ln_fine if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_electores ln_fine lfine_2016 if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
test ln_fine+lfine_2016==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")
reghdfe ln_votos_emitidos ln_fine  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_votos_emitidos ln_fine lfine_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
test ln_fine+lfine_2016==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")

******************************************************************************************
*Table 5: The Marginal Effect of the Abstention Fine on Invalid and Blank Votes
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\Table5.tex", dec(3) bracket nocons nor2
reghdfe turnout fine_a if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  replace addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_2016 if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2016==0
local temp: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp'")
reghdfe spoiled_elec fine_a if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe spoiled_elec fine_a fine_2016 if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2016==0
local temp: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp'") tex(frag)

******************************************************************************************
*Table A1: Assignment of Districts to Poverty Categories in 2006 and 2010
******************************************************************************************
tab category_10 category_06 if year==2016 & runoff==1

******************************************************************************************
*Table B1: Main Results Clustering by Region (Wild Cluster Bootstrap)
******************************************************************************************
preserve
clear matrix
clear mata
keep turnout fine_a electores_01 id ubigeo region  ln_turnout ln_fine ln_electores spoiled* runoff province_id
compress
recast long electores_01
global out outreg2 using "$P_RESULTS\Tables\TableB1.tex",  bracket nocons nor2 dec(3) keep(fine_a)
reghdfe turnout fine_a   [aweight=electores_01], a(ubigeo id) vce(cluster region) noomitted
matrix dof= e(dof_table)
local d = dof[1,2]
local r2=e(r2_within)
sum `e(depvar)' if e(sample) [aweight=electores_01]
local m = r(mean)
reghdfe turnout fine_a  i.id  [aweight=electores_01], a(ubigeo) vce(cluster region) noomitted
boottest fine_a,  seed(999)
matrix betas= e(b)
local beta = betas[1,1]
local p =  r(p)
local p: di  %12.3fc `p' 
reghdfe turnout fine_a   [aweight=electores_01], a(id ubigeo) vce(cluster region) noomitted
${out}  replace addstat(Districts, `d', Mean of dep. var, `m', R-squared, `r2') addtext(p-value,`p'  ,District FE, Yes, Election-Province-Category '06 FE, Yes, Weighted, Yes )
global out outreg2 using "$P_RESULTS\Tables\TableB1.tex",  bracket nocons nor2 dec(3) keep(ln_fine)
reghdfe ln_turnout ln_fine  [aweight=electores_01], a( ubigeo id) vce(cluster region) noomitted
matrix dof= e(dof_table)
local d = dof[1,2]
local r2=e(r2_within)
sum `e(depvar)' if e(sample) [aweight=electores_01]
local m = r(mean)
reghdfe ln_turnout ln_fine  i.id  [aweight=electores_01], a(ubigeo) vce(cluster region) noomitted
boottest ln_fine==0, seed(999)
matrix betas= e(b)
local beta = betas[1,1]
local t = r(t) 
local p =  r(p)
local p: di  %12.3fc `p' 
reghdfe ln_turnout ln_fine  [aweight=electores_01], a(id ubigeo) vce(cluster region) noomitted
${out}  addstat(Districts, `d', Mean of dep. var, `m', R-squared, `r2') addtext(p-value,`p'  ,District FE, Yes, Election-Province-Category '06 FE, Yes, Weighted, Yes )
reghdfe ln_electores ln_fine if runoff==0 [aweight=electores_01], a( ubigeo id) vce(cluster region) noomitted
matrix dof= e(dof_table)
local d = dof[1,2]
local r2=e(r2_within)
sum `e(depvar)' if e(sample) [aweight=electores_01]
local m = r(mean)
reghdfe ln_electores ln_fine  i.id if runoff==0  [aweight=electores_01], a(ubigeo) vce(cluster region) noomitted
boottest ln_fine==0, seed(999)
matrix betas= e(b)
local beta = betas[1,1]
local t = r(t) 
local p =  r(p)
local p: di  %12.3fc `p' 
reghdfe ln_electores ln_fine if runoff==0 [aweight=electores_01], a(id ubigeo) vce(cluster region) noomitted
${out}  addstat(Districts, `d', Mean of dep. var, `m', R-squared, `r2') addtext(p-value,`p'  ,District FE, Yes, Election-Province-Category '06 FE, Yes, Weighted, Yes )
global out outreg2 using "$P_RESULTS\Tables\TableB1.tex", dec(3) bracket nocons nor2 keep(fine_a)
reghdfe spoiled_elec fine_a   if runoff==0  [aweight=electores_01], a(ubigeo id) vce(cluster region) noomitted
matrix dof= e(dof_table)
local d = dof[1,2]
local r2=e(r2_within)
sum `e(depvar)' if e(sample) [aweight=electores_01]
local m = r(mean)
reghdfe spoiled fine_a  i.id if runoff==0 [aweight=electores_01], a(ubigeo) vce(cluster region) noomitted
boottest fine_a==0, seed(999)
matrix betas= e(b)
local beta = betas[1,1]
local t = r(t) 
local p =  r(p)
local p: di  %12.3fc `p' 
reghdfe spoiled fine_a   if runoff==0 [aweight=electores_01], a(id ubigeo) vce(cluster region) noomitted
${out}  addstat(Districts, `d', Mean of dep. var, `m', R-squared, `r2') addtext(p-value,`p'  ,District FE, Yes, Election-Province-Category '06 FE, Yes, Weighted, Yes )
restore

******************************************************************************************
*Table B2: Event-study estimates of the effect of the reform on turnout and registration
******************************************************************************************
preserve
gen round 	  = 1	 if runoff==0
replace round = 2  	 if runoff==1
foreach x of numlist 1 3 {
	foreach y of numlist 2001 2006 2011 2016{
		foreach z of numlist 1/2{
				if `y'!=2006|`z'!=2{
					gen c10_`x'_`y'_r`z'=(category_10==`x'&year==`y'&round==`z')
				}
		}
	}
}
global out outreg2 using "$P_RESULTS\Tables\TableB2.tex",label tex(fragment) dec(3) bracket nocons  nor2
reghdfe turnout c10_1_2001_r1-c10_3_2016_r2  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
parmest,saving("$P_INTERMEDIATE/event_turnout_DDD", replace)
mat M = e(dof_table)
local M1 = M[1,1]
${out}  replace addstat(Districts, `M1') addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Sample, All)
reghdfe ln_electores c10_1_2001_r1 c10_1_2011_r1 c10_1_2016_r1 c10_3_2001_r1  c10_3_2011_r1 c10_3_2016_r1  if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
parmest,saving("$P_INTERMEDIATE/event_electores_DDD", replace)
mat M = e(dof_table)
local M1 = M[1,1]
${out}  append addstat(Districts, `M1') addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Election-Province FE, No, Sample, All)
restore

******************************************************************************************
*Table B3: The Marginal Effect of the Abstention Fine on Voter Turnout in Run-Off elections
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\TableB3.tex", bracket nocons dec(3) nor2
reghdfe turnout fine_a  if runoff==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace ctitle(Baseline) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout    vs_runoff    if runoff==1   [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle() addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout  fine_a  vs_runoff    if runoff==1   [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle() addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout  fine_a  vs_runoff fine_vs   if runoff==1   [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  ctitle() addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)

******************************************************************************************
*Table B4: Heterogeneous effects by Age of the Electorate
******************************************************************************************
*Panel A
global out outreg2 using "$P_RESULTS\Tables\TableB4_a.tex", bracket nocons nor2 dec(3)
reghdfe turnout fine_a fine_age_avg  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_age_avg fine_any_poor  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_age_mid fine_age_high  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_age_mid fine_age_high fine_any_poor  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)

*Panel B
global out outreg2 using "$P_RESULTS\Tables\TableB4_b.tex", bracket nocons nor2 dec(3)
reghdfe ln_turnout ln_fine ln_fine_age_avg [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_turnout ln_fine ln_fine_age_avg lfine_any_poor  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_turnout ln_fine ln_fine_age_mid ln_fine_age_high  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_turnout ln_fine ln_fine_age_mid ln_fine_age_high lfine_any_poor  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) tex(frag)

******************************************************************************************
*Table C1: Effects of Expected Fine on Turnout
******************************************************************************************
preserve 

global out outreg2 using "$P_RESULTS\Tables\TableC1.tex", bracket nocons nor2 dec(3)
gen fine_set=fine_a*set1
reghdfe turnout fine_set  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
gen temp1=e(sample)
${out} replace 
drop fine_set
foreach x of numlist 2/3{
gen fine_set=fine_a*set`x'
reghdfe turnout fine_set  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
gen temp`x'=e(sample)
${out}
drop fine_set
}
foreach x of numlist 1/3{
gen lfine_set=ln((fine_a*set`x')+0.01)
reghdfe ln_turnout lfine_set  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
if `x'<3{
${out}
}
if `x'==3{
${out} tex(frag)
}
drop lfine_set
}
restore

******************************************************************************************
*Table C3: Improved Enforcement and the Long-run Effect of the Fine on Turnout
******************************************************************************************
preserve
drop if settled>1&settled!=.
global out outreg2 using "$P_RESULTS\Tables\TableC3.tex", dec(3) bracket nocons nor2
reghdfe turnout fine_a fine_2016 target_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} replace ctitle(target) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_2016 if region!=14&province_id!=190 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} ctitle(drop_LyC) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_2016 provcap_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} ctitle(capitals) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_2016 if provcap==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} ctitle(drop_cap) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_2016 chg_set_2016 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} ctitle(chg_set) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe turnout fine_a fine_2016 target_2016 provcap_2016 chg_set_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} ctitle(all) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) tex(frag)
restore

******************************************************************************************
*Table D1: The Value of the Abstention Fine and Voter Registration: Heterogeneous Effects by Distance to Districts with Lower Fine
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables/TableD1.tex",  bracket nocons nor2 dec(3)  
reghdfe ln_electores ln_fine lfine_neigh_min if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
test ln_fine+lfine_neigh_min==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")
reghdfe ln_electores  lfine_dum_5 lfine_dum_10  lfine_dum_more10 if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}   addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes )

******************************************************************************************
*Table D2: The Value of the Abstention Fine and Age-speciffic Voter Registration, controlling for predicted voters
******************************************************************************************
preserve
gen ln_voters_hat=ln_voters_hat_1820
global out outreg2 using "$P_RESULTS\Tables\TableD2.tex", bracket nocons nor2 dec(3)
reghdfe ln_entre_18_20 ln_fine ln_voters_hat if runoff==0  [aweight=electores_01],absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) replace
replace ln_voters_hat=ln_voters_hat_2129
reghdfe ln_entre_21_29 ln_fine ln_voters_hat if runoff==0  [aweight=electores_01],absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
replace ln_voters_hat=ln_voters_hat_3035
reghdfe ln_entre_30_35 ln_fine ln_voters_hat if runoff==0  [aweight=electores_01],absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
replace ln_voters_hat=ln_voters_hat_3650
reghdfe ln_entre_36_50 ln_fine ln_voters_hat if runoff==0  [aweight=electores_01],absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
replace ln_voters_hat=ln_voters_hat_5175
reghdfe ln_entre_51_75 ln_fine ln_voters_hat if runoff==0  [aweight=electores_01],absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
replace ln_voters_hat=ln_voters_hat_76
reghdfe ln_mayores_75 ln_fine ln_voters_hat if runoff==0  [aweight=electores_01],absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) tex(frag)
drop ln_voters_hat
restore

******************************************************************************************
*Table D3: The Value of the Abstention Fine, Nighttime lights and Migration
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\TableD3.tex", bracket nocons nor2 dec(3)
reghdfe lndn fine_a [aweight=electores_01] if runoff==0,absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_electores fine_a [aweight=electores_01] if runoff==0&year<=2011,absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_electores fine_a lndn [aweight=electores_01] if runoff==0&year<=2011,absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe born_d fine_a [aweight=electores_01] if runoff==0,absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_electores fine_a [aweight=electores_01] if runoff==0&year>=2006&born_d!=.,absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_electores fine_a born_district [aweight=electores_01] if runoff==0&year>=2006,absorb(ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) tex(frag)

******************************************************************************************
*Table D4: The Value of the Abstention Fine and Age-speciffic Voter Registration, controlling for access to DNI
******************************************************************************************
preserve
reghdfe turnout fine_a chg_dni_2016_prepost   [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
gen in_model = e(sample)
keep if in_model==1

*Panel A
global out outreg2 using "$P_RESULTS\Tables\TableD4_a.tex", bracket nocons nor2 dec(3)
reghdfe ln_entre_18_20  ln_fine  if runoff==1&in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} replace  ctitle(18-20) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_21_29 ln_fine  if runoff==1 &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(21-29) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_30_35 ln_fine  if runoff==1  &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(30-35) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_36_50 ln_fine  if runoff==1  &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(36-50) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_51_75 ln_fine  if runoff==1 &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(51-74) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_mayores_75 ln_fine  if runoff==1  &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(75+) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) tex(frag)

*Panel B
global out outreg2 using "$P_RESULTS\Tables\TableD4_b.tex", bracket nocons nor2 dec(3)
reghdfe ln_entre_18_20  ln_fine chg_dni_2011_prepost chg_dni_2016_prepost if runoff==1&in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} replace  ctitle(18-20) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_21_29 ln_fine chg_dni_2011_prepost chg_dni_2016_prepost if runoff==1 &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(21-29) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_30_35 ln_fine chg_dni_2011_prepost chg_dni_2016_prepost if runoff==1  &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(30-35) addstat(Districts,`M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_36_50 ln_fine chg_dni_2011_prepost chg_dni_2016_prepost if runoff==1  &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(36-50) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_entre_51_75 ln_fine chg_dni_2011_prepost chg_dni_2016_prepost if runoff==1 &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(51-74) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) 
reghdfe ln_mayores_75 ln_fine chg_dni_2011_prepost chg_dni_2016_prepost if runoff==1  &in_model==1 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  ctitle(75+) addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes) tex(frag)
restore

******************************************************************************************
*Table D5: The Value of the Fine and Voter Turnout controlling for Registration
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\TableD5.tex", bracket nocons nor2 dec(3)
reghdfe ln_turnout ln_fine ln_electores  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe ln_turnout ln_fine lfine_2016 ln_electores  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
test ln_fine+lfine_2016==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")

preserve
replace ln_fine=fine_a
replace lfine_2016=fine_2016 
reghdfe turnout ln_fine ln_electores  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout ln_fine lfine_2016 ln_electores  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)	
test ln_fine+lfine_2016==0
local temp1: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'") tex(frag)
restore

******************************************************************************************
*Table F1: Vote Share for Winner and Runner-up in First Round
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables/TableF1.tex",  bracket nocons nor2 dec(3)  
reghdfe vs_winner fine_a  if runoff==0 [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} replace   addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe vs_runner    fine_a    if runoff==0   [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}    addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe vs_2candidates    fine_a    if runoff==0   [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[1,1]
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}    addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)

******************************************************************************************
*Table F2: The Marginal Effect of the Abstention Fine on Invalid and Blank Votes: Full sample
******************************************************************************************
global out outreg2 using "$P_RESULTS\Tables\TableF2.tex", dec(3) bracket nocons nor2
reghdfe turnout fine_a  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  replace addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe turnout fine_a fine_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2016==0
local temp: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp'")
reghdfe spoiled_elec fine_a  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out}  addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe spoiled_elec fine_a fine_2016  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2016==0
local temp: di %4.3fc r(p)
mat M = e(dof_table)
local M1 = e(M1)
sum `e(depvar)' if e(sample) [aweight=electores_01]
${out} addstat(Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp'") tex(frag)

******************************************************************************************
*Figure 1: The Abstention Fine by Election and Fine Category
******************************************************************************************
twoway (connected fine_extreme_poor_a year,msymbol(triangle) msangle(180)) (connected fine_no_poor_a year,msymbol(triangle)) (connected fine_poor_a year,msymbol(square)) (scatter min_wage_day year, msymbol(x) msize(vlarge) mcolor(gs06)) if ubigeo==10102&runoff==0, ///
ytitle(Abstention Fine (S/)) ylabel(0(20)140, angle(horizontal)) xtitle("National election year") xline(2006.5 2010.5,lpattern(dash)) xlabel(2001 2006 2011 2016) xscale(range(2000.5 2016.5)) ///
text(140 2008.2 "Initial assignment:" "October 2006" 140 2012.5 "Adjusted assignment:" "October 2010",size(small) justification(left)) ///
legend(order(1 "Low fine" 3 "Medium fine" 2 "High fine" 4 "Daily min. wage")rows(1) size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
 name(fine_year,replace)
graph export "$P_RESULTS\Figures\Figure1.pdf", as(pdf) replace

******************************************************************************************
*Figure 2: The Reform to the Abstention Fine and Voter Turnout
******************************************************************************************
preserve
use "$P_INTERMEDIATE/event_turnout_DDD",clear
drop if parm=="_cons"
gen cat=substr(parm,5,1)
gen year=substr(parm,7,4)
gen round=substr(parm,13,1)
destring cat year round,replace
set obs 16
replace year = 2006 if year==.
replace round = 2 if round==.
mvencode estimate min95 max95,mv(0)
replace cat=1 in 15
replace cat=3 in 16
sort year round cat
generate id = 0.8 in 1
replace id = 1.2 in 2
replace id = 1.8 in 3
replace id = 2.2 in 4
replace id = 5.8 in 5
replace id = 6.2 in 6
replace id = 6.8 in 7
replace id = 7.2 in 8
replace id = 10.8 in 9
replace id = 11.2 in 10
replace id = 11.8 in 11
replace id = 12.2 in 12
replace id = 15.8 in 13
replace id = 16.2 in 14
replace id = 16.8 in 15
replace id = 17.2 in 16
label define elect 1 "2001 General" 2 "2001 Run-Off" 6 "2006 General" 7 "2006 Run-Off" 11 "2011 General" 12 "2011 Run-Off" 16 "2016 General" 17 "2016 Run-Off"
label values id elect
twoway (rcap min95 max95 id, lcolor(gs7)) (scatter estimate id if cat==3,msymbol(triangle) msangle(180) mcolor(navy)) (scatter estimate id if cat==1,msymbol(triangle) mcolor(maroon)) , ///
ytitle("Turnout (DD estimate)") ylabel(, angle(horizontal)) ///
xtitle(National Election) xscale(range(0 17.2)) xlabel(1 2 6 7 11 12 16 17, valuelabel angle(45)) xline(10, lpattern(dash)) ///
legend(order(2 "Low fine" 3 "High fine" 1 "95% Confidence Interval") r(1))  ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
name(event_turnout_DDD,replace)
graph export "$P_RESULTS\Figures\Figure2.pdf", as(pdf) replace
restore
erase "$P_INTERMEDIATE/event_turnout_DDD.dta"

******************************************************************************************
*Figure 3: The Reform to the Abstention Fine and Voter Registration
******************************************************************************************
preserve
use "$P_INTERMEDIATE/event_electores_DDD",clear
drop if parm=="_cons"
gen cat=substr(parm,5,1)
gen year=substr(parm,7,4)
destring cat year,replace
set obs 8
replace year = 2006 if year==.
replace cat =1 in 7
replace cat =3 in 8
mvencode estimate min95 max95,mv(0)
sort year cat
generate id = 0.9 in 1
replace id = 1.1 in 2
replace id = 1.9 in 3
replace id = 2.1 in 4
replace id = 2.9 in 5
replace id = 3.1 in 6
replace id = 3.9 in 7
replace id = 4.1 in 8
label define elect 1 "2001" 2 "2006" 3 "2011" 4 "2016"
label values id elect
twoway (rcap min95 max95 id, lcolor(gs7)) (scatter estimate id if cat==3,msymbol(triangle) msangle(180) mcolor(navy)) (scatter estimate id if cat==1,msymbol(triangle) mcolor(maroon)) , ///
ytitle("Ln Registered Voters (DD estimate)") ylabel(, angle(horizontal)) ///
xtitle(National Election) xscale(range(1 4.2)) xlabel(1(1)4, valuelabel) xline(2.75, lpattern(dash)) ///
legend(order(2 "Low fine" 3 "High fine" 1 "95% Confidence Interval") r(1))  ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
name(event_electores_DDD,replace)
graph export "$P_RESULTS\Figures\Figure3.pdf", as(pdf) replace
restore
erase "$P_INTERMEDIATE/event_electores_DDD.dta"

******************************************************************************************
*Figure 5: The Reform to the Abstention Fine and Blank or Invalid Votes
******************************************************************************************
preserve
gen round 	  = 1	 if runoff==0
replace round = 2  	 if runoff==1
foreach x of numlist 1 3 {
	foreach y of numlist 2001 2006 2011 2016{
		foreach z of numlist 1/2{
				if `y'!=2006|`z'!=2{
					gen c10_`x'_`y'_r`z'=(category_10==`x'&year==`y'&round==`z')
				}
		}
	}
}

reghdfe spoiled c10_1_2001_r1 c10_1_2011_r1 c10_1_2016_r1 c10_3_2001_r1  c10_3_2011_r1 c10_3_2016_r1  if runoff==0  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
parmest,saving("$P_INTERMEDIATE/event_spoiled_DDD", replace)
restore

preserve
use "$P_INTERMEDIATE/event_spoiled_DDD.dta",clear
drop if parm=="_cons"
gen cat=substr(parm,5,1)
gen year=substr(parm,7,4)
destring cat year,replace
set obs 8
replace year = 2006 if year==.
replace cat =1 in 7
replace cat =3 in 8
mvencode estimate min95 max95,mv(0)
sort year cat
generate id = 0.9 in 1
replace id = 1.1 in 2
replace id = 1.9 in 3
replace id = 2.1 in 4
replace id = 2.9 in 5
replace id = 3.1 in 6
replace id = 3.9 in 7
replace id = 4.1 in 8
label define elect 1 "2001" 2 "2006" 3 "2011" 4 "2016"
label values id elect
twoway (rcap min95 max95 id, lcolor(gs7)) (scatter estimate id if cat==3,msymbol(triangle) msangle(180) mcolor(navy)) (scatter estimate id if cat==1,msymbol(triangle) mcolor(maroon)) , ///
ytitle("Share of Spoiled Votes (DD estimate)") ylabel(, angle(horizontal)) ///
xtitle(National Election) xscale(range(1 4.2)) xlabel(1(1)4, valuelabel) xline(2.75, lpattern(dash)) ///
legend(order(2 "Low fine" 3 "High fine" 1 "95% Confidence Interval") r(1))  ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
name(event_spoiled_DDD,replace)
graph export "$P_RESULTS\Figures\Figure5.pdf", as(pdf) replace
restore
erase "$P_INTERMEDIATE/event_spoiled_DDD.dta"

******************************************************************************************
*Figure A1: Voter Turnout in National Elections
******************************************************************************************
preserve 
fcollapse (sum) votos_emitidos electores,by(year runoff)
gen id=year
replace year=year-0.55 if runoff==0
replace year=year+0.55 if runoff==1
gen turnout=votos/elec
twoway (bar turnout year if runoff==0, fcolor(gs4)) (bar turnout year if runoff==1, fcolor(gs8)), ytitle(Aggregate Voter Turnout) ylabel(0.8(0.02)0.9, angle(horizontal)) xtitle(National Election) xlabel(2001 2006 2011 2016) ///
legend(order(1 "General Election" 2 "Presidential Run-Off")) scheme(sj) name(turnout_aggr, replace) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph export "$P_RESULTS\Figures\FigureA1.pdf", as(pdf) replace
restore

******************************************************************************************
*Figure B1: The Reform to the Abstention Fine and Turnout by 2006 Poverty Category
******************************************************************************************
preserve
gen round = 1 if runoff==0
replace round = 2 if runoff==1
foreach x of numlist 2 4 5 7{
	foreach y of numlist 2001 2006 2011 2016{
		foreach z of numlist 1/2{
				if `y'!=2006|`z'!=2{
					gen c0610_`x'_`y'_r`z'=(category_0610==`x'&year==`y'&round==`z')
				}
		}
	}
}
reghdfe turnout c0610_2_2001_r1-c0610_7_2016_r2  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
parmest,saving("$P_INTERMEDIATE/event_turnout_DDD_full", replace)
restore

preserve
use "$P_INTERMEDIATE/event_turnout_DDD_full.dta",clear
drop if parm=="_cons"
gen cat=substr(parm,7,1)
gen year=substr(parm,9,4)
gen round=substr(parm,15,1)
destring cat year round,replace
set obs 32
replace year = 2006 if year==.
replace round = 2 if round==.
mvencode estimate min95 max95,mv(0)
replace cat=2 in 29
replace cat=4 in 30
replace cat=5 in 31
replace cat=7 in 32
sort year round cat
gen id = 1 if year==2001&round==1
replace id = 3 if year==2001&round==2
replace id = 7 if year==2006&round==1
replace id = 9 if year==2006&round==2
replace id = 13 if year==2011&round==1
replace id = 15 if year==2011&round==2
replace id = 19 if year==2016&round==1
replace id = 21 if year==2016&round==2
replace id=id-0.45 if cat==2
replace id=id-0.15 if cat==4
replace id=id+0.15 if cat==5
replace id=id+0.45 if cat==7
label define elect 1 "2001 General" 3 "2001 Run-Off" 7 "2006 General" 9 "2006 Run-Off" 13 "2011 General" 15 "2011 Run-Off" 19 "2016 General" 21 "2016 Run-Off"
label values id elect
twoway (rcap min95 max95 id, lcolor(gs8))(scatter estimate id if cat==2,msize(small) msymbol(triangle) mfcolor(red) mlcolor(red)) ///
(scatter estimate id if cat==4,msize(small) msymbol(triangle) msangle(180)  mfcolor(eltblue) mlcolor(eltblue)) ///
(scatter estimate id if cat==5,msize(small) msymbol(triangle) mfcolor(white) mlcolor(red)) ///
(scatter estimate id if cat==7,msize(small) msymbol(triangle) msangle(180) mfcolor(white) mlcolor(eltblue)), ///
ytitle("Turnout (DD estimate)") ylabel(-0.05(0.025)0.05, angle(horizontal)) ///
xtitle(National Election) xscale(range(0 21.2)) xlabel(1 3 7 9 13 15 19 21, valuelabel angle(45)) xline(11.7, lpattern(dash)) ///
legend(order(2 "Medium fine '06 to High fine '10" 3 "Medium fine '06 to Low fine '10" 4 "Low fine '06 to High fine '10" 5 "Low fine '06 to Low fine '10") r(2) size(small)) scheme(sj) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) name(event_turnout_DDD_full,replace)
graph export "$P_RESULTS\Figures\FigureB1.pdf", as(pdf) replace
restore
erase "$P_INTERMEDIATE/event_turnout_DDD_full.dta"

******************************************************************************************
*Figure B2: The Reform to the Abstention Fine and Turnout: Heterogeneous Effects by Share of Poor
******************************************************************************************
preserve
gen sh_poor=non_extreme+extreme
gen round 	  = 1	 if runoff==0
replace round = 2  	 if runoff==1

*calculate median of poverty rate by category
sum sh_poor if category_10==1,det
sum sh_poor if category_10==2,det
sum sh_poor if category_10==3,det

*create sub-groups by poverty within category
gen cat_poor=1 if category_10==1&sh_poor>=.4054254
replace cat_poor=2 if category_10==1&sh_poor<.4054254
replace cat_poor=3 if category_10==2&sh_poor>=.7073303
replace cat_poor=4 if category_10==2&sh_poor<.7073303
replace cat_poor=5 if category_10==3&sh_poor>=.8215725
replace cat_poor=6 if category_10==3&sh_poor<.8215725
tab cat_poor,miss

*create dummies for regression
foreach x of numlist 1 2 4 5 6 {
	foreach y of numlist 2001 2006 2011 2016{
		foreach z of numlist 1/2{
				if `y'!=2006|`z'!=2{
					gen cat_`x'_`y'_r`z'=(cat_poor==`x'&year==`y'&round==`z')
				}
		}
	}
}

*event study
reghdfe turnout cat_1_2001_r1- cat_6_2016_r2  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
parmest,saving("$P_INTERMEDIATE/event_poor", replace)

*draw graph
use "$P_INTERMEDIATE/event_poor",clear
drop if parm=="_cons"
gen group=substr(parm,5,1)
gen year=substr(parm,7,4)
gen round=substr(parm,13,1)
destring group year round,replace
set obs 40
replace year = 2006 if year==.
replace round = 2 if round==.
mvencode estimate min95 max95,mv(0)
replace group=1 in 36
replace group=2 in 37
replace group=4 in 38
replace group=5 in 39
replace group=6 in 40
sort year round group
gen id = 1 if year==2001&round==1
replace id = 3 if year==2001&round==2
replace id = 7 if year==2006&round==1
replace id = 9 if year==2006&round==2
replace id = 13 if year==2011&round==1
replace id = 15 if year==2011&round==2
replace id = 19 if year==2016&round==1
replace id = 21 if year==2016&round==2
replace id=id-0.6 if group==1
replace id=id-0.3 if group==2
replace id=id+0.3 if group==5
replace id=id+0.6 if group==6
label define elect 1 "2001 General" 3 "2001 Run-Off" 7 "2006 General" 9 "2006 Run-Off" 13 "2011 General" 15 "2011 Run-Off" 19 "2016 General" 21 "2016 Run-Off"
label values id elect

twoway (rcap min95 max95 id, lcolor(gs8))(scatter estimate id if group==1,msize(small) msymbol(triangle) mfcolor(red) mlcolor(red)) (scatter estimate id if group==2,msize(small) msymbol(triangle) mfcolor(white) mlcolor(red)) (scatter estimate id if group==4,msize(small) msymbol(square) mfcolor(white) mlcolor(green)) (scatter estimate id if group==5,msize(small) msymbol(triangle) msangle(180) mfcolor(eltblue) mlcolor(eltblue)) (scatter estimate id if group==6,msize(small) msymbol(triangle) msangle(180) mfcolor(white) mlcolor(eltblue)), ytitle("Turnout (DD estimate)") ylabel(, angle(horizontal)) xtitle(National Election) xscale(range(0 22)) xlabel(1 3 7 9 13 15 19 21, valuelabel angle(45)) xline(11.7, lpattern(dash)) legend(order(2 "high fine, high poverty" 5 "low fine, high poverty" 3 "high fine, low poverty" 4 "medium fine, low poverty" 6 "low fine, low poverty") r(2) holes(2) size(small)) scheme(sj) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) name(event_hetero_poor,replace) 
graph export "$P_RESULTS\Figures\FigureB2.pdf", as(pdf) replace

erase "$P_INTERMEDIATE/event_poor.dta"
restore
******************************************************************************************
*Figure B3: Election-speciffic Estimates of the Marginal Effect of the Abstention Fine on Turnout and the Elasticity
******************************************************************************************
preserve
reghdfe turnout fine_r1_11 fine_r2_11 fine_r1_16 fine_r2_16  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
parmest,saving("$P_INTERMEDIATE/effect_change_DDD", replace)
restore

preserve
reghdfe ln_turnout lfine_r1_11 lfine_r2_11 lfine_r1_16 lfine_r2_16  [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test lfine_r1_11==lfine_r2_11
test lfine_r1_16==lfine_r2_16
test lfine_r1_11==lfine_r1_16
test lfine_r2_11==lfine_r2_16
parmest,saving("$P_INTERMEDIATE/elasticity_change_DDD", replace)
restore

preserve
use "$P_INTERMEDIATE/effect_change_DDD",clear
drop if parm=="_cons"
gen id=_n
gen runoff=(id==2|id==4)
replace id=id-0.1 if id==1|id==3
replace id=id-0.9 if id==2|id==4
replace id=id-1 if id>2
label define elect 1 "2011" 2 "2016"
label values id elect
twoway (scatter estimate id if runoff==0) (scatter estimate id if runoff==1) (rcap min95 max95 id) ///
(pci 0.05 0.8 0.05 1.2,lcolor(black)) (pci 0.0475 0.8 0.0525 0.8,lcolor(black)) (pci 0.0475 1.2 0.0525 1.2,lcolor(black)) ///
(pci 0.035 1.8 0.035 2.2,lcolor(black)) (pci 0.0325 1.8 0.0375 1.8,lcolor(black)) (pci 0.0325 2.2 0.0375 2.2,lcolor(black)), ///
ytitle("Effect on turnout of a S/ 100 fine increase") ylabel(, angle(horizontal)) ///
xtitle("National Election") xscale(range(0.75 2.25)) xlabel(1 2, valuelabel) ///
text(0.054 1 "p=0.0132" 0.032 2 "p=0.0000") /// 
legend(order(1 "General Election" 2 "Presidential Run-Off" 3 "95% C.I.") r(1)) scheme(sj) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
name(effect_change_DDD,replace)
graph export "$P_RESULTS\Figures\FigureB3_a.pdf", as(pdf) replace
restore

preserve
use "$P_INTERMEDIATE/elasticity_change_DDD",clear
drop if parm=="_cons"
gen id=_n
gen runoff=(id==2|id==4)
replace id=id-0.1 if id==1|id==3
replace id=id-0.9 if id==2|id==4
replace id=id-1 if id>2
label define elect 1 "2011" 2 "2016"
label values id elect

twoway (scatter estimate id if runoff==0) (scatter estimate id if runoff==1) (rcap min95 max95 id) ///
(pci 0.03 0.8 0.03 1.2,lcolor(black)) (pci 0.0275 0.8 0.0325 0.8,lcolor(black)) (pci 0.0275 1.2 0.0325 1.2,lcolor(black)) ///
(pci 0.02 1.8 0.02 2.2,lcolor(black)) (pci 0.0175 1.8 0.0225 1.8,lcolor(black)) (pci 0.0175 2.2 0.0225 2.2,lcolor(black)), ///
text(0.033 1 "p=0.0071" 0.0175 2 "p=0.0000") /// 
ytitle("Elasticity estimate") ylabel(, angle(horizontal)) ///
xtitle("National Election") xscale(range(0.75 2.25)) xlabel(1 2, valuelabel) ///
legend(order(1 "General Election" 2 "Presidential Run-Off" 3 "95% C.I.") r(1)) scheme(sj) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
name(effect_change_DDD,replace)
graph export "$P_RESULTS\Figures\FigureB3_b.pdf", as(pdf) replace
restore
erase "$P_INTERMEDIATE/effect_change_DDD.dta"
erase "$P_INTERMEDIATE/elasticity_change_DDD.dta"

******************************************************************************************
*Figure A2: Share of Fines Settled for the 2011 and 2016 Elections
******************************************************************************************
use "$P_CLEAN/FigureA2.dta",clear
graph bar (asis) sh_settled, over(category_10, gap(5)) over(year) asyvars ytitle(Share of Fines Settled) ylabel(0(0.1)0.6, angle(horizontal)) legend(rows(1) size(small)) scheme(sj) graphregion(fcolor(white) ///
lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) name(enforcement_aggr, replace)
graph export "$P_RESULTS\Figures\FigureA2.pdf", as(pdf) replace

******************************************************************************************
*Figure D1: Disentangling the Behavioral Elasticity of Turnout from the Registration Effect
******************************************************************************************
clear
set obs 101
gen prob_vote_move=_n-1
replace prob_vote=prob_vote/100
gen d_lnV_lnF=-0.016
gen d_lnR_lnF=-0.046
gen partial_lnV_lnF=d_lnV_lnF-(prob_vote_move*d_lnR_lnF)
gen sh_elasticity=partial_lnV_lnF/0.0296

twoway (line partial_lnV_lnF prob_vote_move,lcolor(black)), ytitle(Behavioral Elasticity of Turnout) ylabel(-0.016 0 0.013 0.016 0.019 0.022 0.030, angle(horizontal) format(%4.3f)) xtitle(Turnout | {&Delta} Registered Address) xline(0.83, lcolor(eltgreen) lpattern(solid)) xline(0.77, lcolor(gold) lpattern(dash)) xline(0.71, lcolor(orange) lpattern(dash_dot)) xline(0.64, lcolor(red) lpattern(shortdash)) text(0.0296 0.62 "3SD",size(vsmall)) text(0.0296 0.69 "2SD",size(vsmall)) text(0.0296 0.75 "1SD",size(vsmall)) text(0.0296 0.81 "Avg.",size(vsmall)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) legend(off) name(registration_bounds,replace)
graph export "$P_RESULTS\Figures\FigureD1.pdf", as(pdf) name("registration_bounds") replace

******************************************************************************************
*Table 6: The Marginal Effect of the Abstention Fine on Political Attitudes and Behaviors
******************************************************************************************
use "$P_CLEAN/Table6.dta",clear

global controls = "gender primary_less highschool"
global out outreg2 using "$P_RESULTS\Tables/Table6.tex", bracket nocons nor2 dec(3) label keep(fine_a )
reghdfe trust_parties1  fine_a $controls  [aweight=factor] if belong!=. , absorb(age ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[2,1]
sum `e(depvar)' if e(sample)  [aweight=factor]
${out} replace   addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Years included:, 2004-2016)
reghdfe belong_party fine_a $controls [aweight=factor] if trust_parties1!=. , absorb( age  ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[2,1]
sum `e(depvar)' if e(sample)  [aweight=factor]
${out}    addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Years included:, 2004-2016)
reghdfe interest fine_a $controls  [aweight=factor] if frec_freq!=.,absorb( age  ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
mat M = e(dof_table)
local M1 = M[2,1]
sum `e(depvar)' if e(sample)  [aweight=factor]
${out}   addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Years included:, 2004-2011)
reghdfe frec_freq  fine_a   $controls [aweight=factor] if interest!=., absorb(age ubigeo i.year#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample)  [aweight=factor] 
${out}    addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, Years included:, 2004-2011) tex(frag)

******************************************************************************************
*Table C2: The Marginal Effect of the Abstention Fine on Settlement of Outstanding Fines
******************************************************************************************
use "$P_CLEAN/TableC2.dta",clear

global out outreg2 using "$P_RESULTS\Tables\TableC2.tex",bracket nocons nor2 dec(3)
reghdfe settled fine_a [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  replace addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe settled fine_a fine_2014p [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2014p==0
local temp1: di %4.3fc r(p)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")
reghdfe paid fine_a [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe paid fine_a fine_2014p [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2014p==0
local temp1: di %4.3fc r(p)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'")
reghdfe excuse fine_a [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out} addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes)
reghdfe excuse fine_a fine_2014p [aweight=electores_01],absorb(ubigeo i.date#i.category_06#i.province_id) cluster(province_id)
test fine_a+fine_2014p==0
local temp1: di %4.3fc r(p)
sum `e(depvar)' if e(sample) [aweight=electores_01]
mat M = e(dof_table)
local M1 = M[1,1]
${out}  addstat(Districts, `M1',Mean of dep. var, `r(mean)', R-squared, e(r2_within)) addtext(District FE, Yes, Election-Province-Category '06 FE, Yes, p-value a+b=0,"`temp1'") tex(frag)